# -*- coding: utf-8 -*-
"""
Created on Fri Jan 17 09:42:54 2020

@author: JimmyMo
"""

import matplotlib.pyplot as plt


def build_cartesian_plane(max_quadrant_range):
    """ The quadrant range controls the range of the quadrants"""
    l = []
    zeros = []
    plt.grid(True, color='lightgrey', zorder=0,)
    ax = plt.axes()
    head_width = float(0.05) * max_quadrant_range
    head_length = float(0.1) * max_quadrant_range
    ax.arrow(0, 0, max_quadrant_range, 0, head_width=head_width, head_length=head_length, fc='k', ec='k',zorder=100)
    ax.arrow(0, 0, -max_quadrant_range, 0, head_width=head_width, head_length=head_length, fc='k', ec='k', zorder=100)
    ax.arrow(0, 0, 0, max_quadrant_range, head_width=head_width, head_length=head_length, fc='k', ec='k', zorder=100)
    ax.arrow(0, 0, 0, -max_quadrant_range, head_width=head_width, head_length=head_length, fc='k', ec='k', zorder=100)
    counter_dash_width = max_quadrant_range * 0.01
    dividers = [0,.1,.2,.3,.4, .5, .6, .7, .8, .9, 1]
    for i in dividers:
        plt.plot([-counter_dash_width, counter_dash_width], [i*max_quadrant_range, i*max_quadrant_range], color='k')
        plt.plot([i * max_quadrant_range, i*max_quadrant_range], [-counter_dash_width, counter_dash_width], color='k')
        plt.plot([-counter_dash_width, counter_dash_width], [-i * max_quadrant_range, -i * max_quadrant_range], color='k')
        plt.plot([-i * max_quadrant_range, -i * max_quadrant_range], [-counter_dash_width, counter_dash_width], color='k')
        l.append(i * max_quadrant_range)
        l.append(-i * max_quadrant_range)
        zeros.append(0)
        zeros.append(0)

def kth_root(x,k):
    if k % 2 != 0:
        res = np.power(np.abs(x),1./k)
        return res*np.sign(x)
    else:
        return np.power(np.abs(x),1./k)

import numpy as np
X = np.arange(-10, 10, 0.1)
Y1 = kth_root(X, 2)
Y2 = kth_root(X, 3)
Y3 = kth_root(X, 4)
Y4 = kth_root(X, 5)
# Y4 = np.power(X, 5)
# Y5 = np.power(X, 6)
# Y6 = np.power(X, 7)

build_cartesian_plane(10)
plt.plot(X, Y1, c="b", label="sqrt")
plt.plot(X, Y2, label="3th roots")
plt.plot(X, Y3, label="4th roots")
plt.plot(X, Y4, label="5th roots")
# plt.plot(X, Y4, label="power5")
# plt.plot(X, Y5, label="power6")
# plt.plot(X, Y6, label="power7")

plt.xlim(-5, 5)
plt.ylim(-3, 3)

plt.legend()
plt.show()